package com.rc.saas.tenant.controller.invite;

import com.github.pagehelper.PageInfo;
import com.rc.saas.tenant.base.WebPageInfo;
import com.rc.saas.tenant.search.invite.InviteSearch;
import com.rc.saas.tenant.service.invite.MemberInviteLinkService;
import com.rc.saas.tenant.vo.invite.InviteLinkListVo;
import com.rc.saas.tenant.vo.invite.InviteMemberDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Create by Yang on 2021/5/13
 */
@Controller
@RequestMapping("/inviteLink")
public class InviteLinkController {

    @Autowired
    private MemberInviteLinkService memberInviteLinkService;

    /**
     * 跳转邀请有奖页面
     * 奖励类型 1赠送优惠券  2返利
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String index(Model model) {
        return "/templates/invite/inviteLinkList";
    }

    /**
     * 返利列表数据统计
     *
     * @return
     */
    @RequestMapping(value = "/listInviteLink", method = RequestMethod.GET)
    @ResponseBody
    public WebPageInfo listInviteLink(InviteSearch inviteSearch) {
        if (inviteSearch.getOffset() == null) {
            inviteSearch.setOffset(1);
        }
        if (inviteSearch.getLimit() == null) {
            inviteSearch.setLimit(10);
        }
        PageInfo<InviteLinkListVo> pageInfo = memberInviteLinkService.listInviteLink(inviteSearch);
        WebPageInfo webPageInfo = new WebPageInfo(pageInfo.getList(), Long.valueOf(pageInfo.getTotal()).intValue());
        return webPageInfo;
    }

    /**
     * 跳转到明细表
     * @param
     * @return
     */
    @RequestMapping(value = "/inviteLinkDetail/{memberId}/{inviteSettingId}", method = RequestMethod.GET)
    public String inviteLinkDetail(Model model, @PathVariable("memberId") Long memberId,
                                       @PathVariable("inviteSettingId") Long inviteSettingId) {
        model.addAttribute("memberId", memberId);
        model.addAttribute("inviteSettingId", inviteSettingId);
        return "templates/invite/inviteLinkDetail";
    }

    /**
     * 邀请新用户的明细列表
     *
     * @return
     */
    @RequestMapping(value = "/listInviteLinkDetail", method = RequestMethod.GET)
    @ResponseBody
    public WebPageInfo listInviteLinkDetail(InviteSearch inviteSearch) {
        PageInfo<InviteMemberDetailVo> pageInfo = memberInviteLinkService.listInviteLinkDetail(inviteSearch);
        WebPageInfo webPageInfo = new WebPageInfo(pageInfo.getList(), Long.valueOf(pageInfo.getTotal()).intValue());
        return webPageInfo;
    }
}
